import React, { Component } from 'react';
import { Tree, Icon } from 'antd';

const { TreeNode } = Tree;

// 堆栈树结构显示
class StackTree extends Component {
    onSelect = (selectedKeys, info) => {
        console.log('selected', selectedKeys, info);
    };

    renderTreeNodes = (nodes) => {
        return nodes.map((node) => {
            const { title, key, children } = node;
            if (children) {
                return (
                    <TreeNode title={title} key={key}>
                        {this.renderTreeNodes(children)}
                    </TreeNode>
                );
            }
            return <TreeNode title={title} key={key} />;
        });
    };

    onSelect = (selectedKeys, info) => {
        console.log('selected', selectedKeys, info);
    };

    render() {
        const {treeData} = this.props;
        return <Tree showLine defaultExpandAll switcherIcon={<Icon type="down" />} onSelect={this.onSelect} defaultExpandedKeys={['0']} treeData={treeData} />;
    }
}

export default StackTree;
